"""
https://blog.csdn.net/XMWS_IT/article/details/118331444

pip install xlwings

使用 WPS，需修改 _xlwindows.py 中的内容
修改前
self._xl = COMRetryObjectWrapper(DispatchEx("Excel.Application"))
修改后
self._xl = COMRetryObjectWrapper(DispatchEx("KET.Application"))

"""

import xlwings as xw

# 新建 visible 创建时是否打开
app = xw.App(visible=False, add_book=False)
wb = app.books.add()

# wb就是新建的工作簿(workbook)，下面则对wb的sheet1的A1单元格赋值
wb.sheets['sheet1'].range('A1').value = '人生'
wb.save(r'excel_demo.xlsx')
wb.close()
app.quit()



# # eg:
# # 打开Excel程序，默认设置：程序可见，只打开不新建工作薄，屏幕更新关闭
# app = xw.App(visible=True, add_book=False)
# app.display_alerts = False
# app.screen_updating = False
#
# # 文件位置：filepath，打开test文档，然后保存，关闭，结束程序
# filepath = r'g:\Python Scripts\test.xlsx'
# wb = app.books.open(filepath)
# wb.save()
# wb.close()
# app.quit()

